home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / cat3 / c++ / demangle.z / demangle
Encoding:
Text File  |  2002-10-03  |  9.7 KB  |  268 lines

  1. DEMANGLE(3C)                                           Last changed: 4-6-99
  2.  
  3.  
  4. NNAAMMEE
  5.      ddeemm, ddeemmaannggllee - Demangle C++ external names to a readable format
  6.  
  7. SSYYNNOOPPSSIISS
  8.      ##iinncclluuddee <<ddeemm..hh>>
  9.  
  10.      cccc [_f_l_a_g ...]  _f_i_l_e ... --llmmaannggllee [_l_i_b_r_a_r_y ...]
  11.  
  12.      ttyyppeeddeeff ssttrruucctt DDEEMMAARRGG DDEEMMAARRGG;;
  13.      ttyyppeeddeeff ssttrruucctt DDEEMMCCLL  DDEEMMCCLL;;
  14.      ttyyppeeddeeff ssttrruucctt DDEEMM    DDEEMM;;
  15.  
  16.      iinntt   ddeemmaannggllee((ccoonnsstt cchhaarr **iinn,, cchhaarr **oouutt));;
  17.      iinntt   ddeemm((cchhaarr **ss,, DDEEMM **pp,, cchhaarr **bbuuff));;
  18.  
  19.      vvooiidd  ddeemm__pprriinnttccll((DDEEMMCCLL **pp,, cchhaarr **bbuuff));;
  20.      vvooiidd  ddeemm__pprriinnttaarrgg((DDEEMMAARRGG **pp,, cchhaarr **bbuuff,, iinntt ff));;
  21.      vvooiidd  ddeemm__pprriinnttaarrgglliisstt((DDEEMMAARRGG **pp,, cchhaarr **bbuuff,, iinntt ssvv));;
  22.      iinntt   ddeemm__pprriinntt((DDEEMM **pp,, cchhaarr **bbuuff));;
  23.      vvooiidd  ddeemm__pprriinnttffuunncc((DDEEMM **ddpp,, cchhaarr **bbuuff));;
  24.  
  25. IIMMPPLLEEMMEENNTTAATTIIOONN
  26.      IRIX systems
  27.  
  28. DDEESSCCRRIIPPTTIIOONN
  29.      ddeemm and ddeemmaannggllee are interfaces for user programs to demangle the
  30.      mangled external names that C++ produces for functions, class members,
  31.      etc.
  32.  
  33.      A description of the C++ mangling scheme is provided in the _A_n_n_o_t_a_t_e_d
  34.      _C++ _R_e_f_e_r_e_n_c_e _M_a_n_u_a_l (ARM).
  35.  
  36.  
  37.      The simplest interface to the library is to call the ddeemmaannggllee(())
  38.      function, as follows:
  39.  
  40.               int ret;
  41.               char inbuf[1024];
  42.               char outbuf[MAXDBUF];
  43.  
  44.               if ((ret = demangle(inbuf,  outbuf)) < 0) {
  45.                   /* error! */
  46.               }
  47.  
  48.      The ddeemmaannggllee(()) function will return 0 if it successfully demangled the
  49.      name.  If the demangle operation fails, the input string (iinnbbuuff) is
  50.      copied to the output buffer (oouuttbbuuff).
  51.  
  52.      To attain a finer level of control over the demangling operation, call
  53.      the ddeemm(()) function as follows:
  54.  
  55.               int ret;
  56.               char inbuf[1024];
  57.               DEM d;
  58.               char sbuf[MAXDBUF];
  59.  
  60.               ret = dem(inbuf, &d, sbuf);
  61.  
  62.      where iinnbbuuff is the input name, dd the data structure that ddeemm(()) fills
  63.      up, and ssbbuuff is used as an internal buffer that the demangler uses to
  64.      allocate this data structure (dd will contain pointers into ssbbuuff).
  65.  
  66.      Note that the first parameter to ddeemm(()) is of type cchhaarr **, not ccoonnsstt
  67.      cchhaarr **:: A call to ddeemm(()) may alter its input.
  68.  
  69.      There is a constant MMAAXXDDBBUUFF defined in dem.h.  This is the maximum
  70.      size of buffer required for an unmangled name's data structure.
  71.  
  72.      ddeemm(()) returns -1 if there is an error, otherwise it returns 0.
  73.  
  74.      The <<ddeemm..hh>> include file has comments describing each field in the
  75.      data structures.  The data structures are somewhat complicated by the
  76.      need to handle nested types and function arguments which themselves
  77.      are function pointers with their own arguments.
  78.  
  79.      The following functions can be used to format this data structure:
  80.  
  81.      * ddeemm__pprriinntt(()) formats a complete demangled name from the contents of
  82.        the DEM structure.
  83.  
  84.      * ddeemm__pprriinnttccll(()) formats just a class name.
  85.  
  86.      * ddeemm__pprriinnttffuunncc(()) format just a function name.
  87.  
  88.      * ddeemm__pprriinnttaarrgg(()) formats a single function argument.
  89.  
  90.      * ddeemm__pprriinnttaarrgglliisstt(()) formats a complete function argument list.
  91.  
  92. DDIIAAGGNNOOSSTTIICCSS
  93.      ddeemmaannggllee(()), ddeemm(()), and ddeemm__pprriinntt(()) return 0 if they succeed, and -1 if
  94.      the input name is not a valid mangled name (or if there are any other
  95.      error conditions, like passing in invalid arguments).
  96.  
  97. EEXXAAMMPPLLEESS
  98.      This particular application reads from standard input and displays the
  99.      class name for each mangled name read, or "(none)" on errors and C
  100.      functions/data.
  101.  
  102.  
  103.               #include <stdio.h>
  104.               #include <dem.h>
  105.  
  106.               main()
  107.               {
  108.                   char sbuf[MAXDBUF];
  109.                   DEM d;
  110.                   int ret;
  111.                   char buf[1024];
  112.                   char buf2[1024];
  113.  
  114.                   while (gets(buf) != NULL) {
  115.                       ret = dem(buf, &d, sbuf);
  116.                       if (ret || d.cl == NULL) {
  117.                           printf("%s --> (none)\n", buf);
  118.                       }
  119.                       else {
  120.                           dem_printcl(d.cl, buf2);
  121.                           printf("%s --> %s\n", buf, buf2);
  122.                       }
  123.                   }
  124.               }
  125.  
  126. TTYYPPEENNAAMMEESS
  127.      The demangler handles mangled class typenames, whether they are
  128.      simple, nested, or template classes.  For example:
  129.  
  130.               A__pt__2_i --> A<int>
  131.  
  132.               __Q2_1A1B --> A::B
  133.  
  134. LLOOCCAALL VVAARRIIAABBLLEESS
  135.      The demangler also handles local variables of the following form:
  136.  
  137.               __nnnxxx
  138.  
  139.      For example:
  140.  
  141.               __2x --> x
  142.  
  143. BBUUGGSS AANNDD AAMMBBIIGGUUIITTIIEESS
  144.      1. "signed" and "volatile" encodings are not handled.
  145.  
  146.      2. The encoding for nested classes as mentioned in the ARM is handled
  147.         slightly differently in cfront; there is a ""__"" after the digit
  148.         after the ""QQ"".
  149.  
  150.      3. A nested class starting with ""QQ"" sometimes has the length encoded
  151.         before it;  the demangler handles either case.
  152.  
  153.      4. The ""TTnnnn"" and ""NNnnnnnn"" notations mentioned in the ARM are not fully
  154.         supported.  It is assumed that the number of the designated
  155.         argument is less than or equal to 9.  So, if you have 11 or more
  156.         arguments, and you want to repeat argument 10 or greater, the
  157.         demangler will reject the encoded name.
  158.  
  159.      5. All literal arguments to templates are assumed to be ccoonnsstt.  For
  160.         example, the non-const literal value 37 is encoded as CCii.
  161.  
  162.      6. Some compilers will add a gratuitous ""__"" before external names.
  163.  
  164.      7. The grammar allows class names up to 999 characters.  This is
  165.         considered important for handling templates.
  166.  
  167. GGRRAAMMMMAARR FFOORR EEXXTTEERRNNAALL NNAAMMEESS
  168.           start       -->     name
  169.  
  170.           ################# COMPLETE NAMES #################
  171.  
  172.           name        -->     sti | std | ptbl | func | data | vtbl |
  173.                               cname3 | local
  174.  
  175.           sti         -->     "__sti" "__" id
  176.  
  177.           std         -->     "__std" "__" id
  178.  
  179.           ptbl        -->     "__ptbl_vec" "__" id
  180.  
  181.           func        -->     "__op" arg funcpost | id funcpost
  182.  
  183.           funcpost    -->     "__" funcpost2 | "__" cname funcpost2
  184.  
  185.           funcpost2   -->     csv "F" arglist
  186.  
  187.           csv         -->     "" | "C" | "S" | "V"
  188.  
  189.           data        -->     id | id "__" cname
  190.  
  191.           vtbl        -->     "__vtbl" "__" cname
  192.  
  193.           local       -->     "__" num regid
  194.  
  195.           ################# CLASS NAMES #################
  196.  
  197.           cname       -->     cname2 | nest
  198.  
  199.           nest        -->     "Q" digit "_" cnamelist
  200.  
  201.           cnamelist   -->     cname2 | cnamelist cname2
  202.  
  203.           cname2      -->     cnlen cnid
  204.  
  205.           cname3      -->     cnid | "__" nest
  206.  
  207.           cnlen       -->     digit | digit digit | digit digit digit
  208.  
  209.           cnid        -->     id | id "__pt__" cnlen "_" arglist
  210.  
  211.           ################# ARGUMENT LISTS #################
  212.  
  213.           arglist     -->     arg | arglist arg
  214.  
  215.           arg         -->     modlist arg2 | "X" modlist arg2 lit
  216.  
  217.           modlist     -->     mod | modlist mod
  218.  
  219.           mod         -->     "" | "U" | "C" | "V" | "S" | "P" | "R" |
  220.                               arr | mptr
  221.  
  222.           arr         -->     "A" num "_"
  223.  
  224.           mptr        -->     "M" cname
  225.  
  226.           arg2        -->     fund | cname | funcp | repeat1 | repeat2
  227.  
  228.           fund        -->     "v" | "c" | "s" | "i" | "l" | "f" |
  229.                               "d" | "r" | "e"
  230.  
  231.           funcp       -->     "F" arglist "_" arg
  232.  
  233.           repeat1     -->     "T" digit | "T" digit digit
  234.  
  235.           repeat2     -->     "N" digit digit | "N" digit digit digit
  236.  
  237.           lit         -->     litnum | zero | litmptr | cnlen id | sptr
  238.  
  239.           litnum      -->     "L" digit lnum | "L" digit digit "_" lnum
  240.  
  241.           litmptr     -->     "LM" num "_" litnum "_" cnlen id
  242.  
  243.           lnum        -->     num | "n" num
  244.  
  245.           sptr        -->     cnlen id "__" cname
  246.  
  247.           zero        -->     0
  248.  
  249.           ################# LOW LEVEL STUFF #################
  250.  
  251.           digit       -->     0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
  252.  
  253.           id          -->     special | regid
  254.  
  255.           special     -->     "__ct" | "__pp" # etc.
  256.  
  257.           regid       -->     letter | letter restid
  258.  
  259.           restid      -->     letter | digit | restid letter |
  260.                               restid digit
  261.  
  262.           letter      -->     "A"-"Z" | "a" - "z" | "_"
  263.  
  264.           num         -->     digit | num digit
  265.  
  266. SSEEEE AALLSSOO
  267.      This man page is available only online.
  268.